import jsonp from '../../src/common/js/jsonp'
import {commonParams, options} from "./config";
import axios from 'axios';
//获取歌手页数据----未使用
export function getSingerList() {
       const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'

       const data = Object.assign({}, commonParams, {
             channel: 'singer',
             page: 'list',
             key: 'all_all_all',
             pagesize: 100,
             pagenum: 1,
             hostUin: 0,
             needNewCode: 0,
             platform: 'yqq',
             g_tk: 1664029744, 
       })

       return jsonp(url, data, options)
 }
//自己测试歌手页数据----测试成功，现在使用的
 export function getSingers() {
       const url = '/api/getSingers'  //调用自定义的接口
    // const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'

    const data = Object.assign({}, commonParams, {
        "-": "getUCGI44418448386643816",
        "g_tk": "5381",
        "loginUin": "0",
        "hostUin": "0",
        "format": "json",
        "inCharset": "utf8",
        "outCharset": "utf-8",
        "notice": "0",
        "platform": "yqq.json",
        "needNewCode": "0",
        "data": {"comm":{"ct":24,"cv":0},"singerList":{"module":"Music.SingerListServer","method":"get_singer_list","param":{"area":-100,"sex":-100,"genre":-100,"index":-100,"sin":0,"cur_page":1}}}
    })
    // return jsonp(url, data, options)
    return axios.get(url, {
        params: data
    }).then((res) => {
        return Promise.resolve(res.data) //es6新语法，返回一个以给定值解析后的Promise对象
    })
}
//获取歌手详情页的数据----自己写的废弃，不是正确的数据，只有专辑数据
// export function getSingeDetail(singerId){
//     const url = '/api/getSingerDetail'//调用自定义的接口
//     const data = Object.assign({},commonParams,{
//         "data":{
//             "req_0":{"module":"music.musichallAlbum.AlbumListServer","method":"GetAlbumList","param":{"singerMid":`${singerId}`,"begin":0,"num":100}},
//             "req_1":{"module":"MvService.MvInfoProServer","method":"GetSingerMvList","param":{"singermid":`${singerId}`,"tagid":0,"start":0,"count":100,"order":0}},
//             "comm":{"g_tk":5381,"uin":0,"format":"json"}}
//     })
//     return axios.get(url,{
//         params:data
//     }).then((res)=>{
//         return Promise.resolve(res.data)
//     })
// }
//获取歌手详情页的数据
export function getSingeDetail(singerId) {
    const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'

    const data = Object.assign({}, commonParams, {
        hostUin: 0,
        needNewCode: 0,
        platform: 'yqq',
        order: 'listen',
        begin: 0,
        num: 100,  //抓取歌手数据100条
        songstatus: 1,
        g_tk: 1664029744, 
        singermid: singerId //传入的不同歌手的Id
    })

    return jsonp(url, data, options)
}

// 获取音乐播放的源
export function getMusicVkey(songmid) {
    const url = '/api/musicvkey'
    const data = Object.assign({}, {
        "-": "getplaysongvkey564623675413412",
        "g_tk": "94551879",
        "loginUin": "1337312569",
        "hostUin": 0,
        "format": "json",
        "inCharset":" utf8",
        "outCharset":" utf-8",
        "notice": 0,
        "platform": "yqq.json",
        "needNewCode": 0,
        "data": {
            "req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"2487804162","songmid":[`${songmid}`],"songtype":[0],"uin":"1337312569","loginflag":1,"platform":"20"}},
            "comm":{"uin":1337312569,"format":"json","ct":24,"cv":0}}
    })
    return axios.get(url, {
      params: data
    }).then((res) => {
      return Promise.resolve(res.data)
    })
}

// 获取音乐播放的歌词
export function getMusicLyric(songmid) {
    const url = '/api/musiclyric'
    const data = Object.assign({}, {
        '-': 'MusicJsonCallback_lrc',
        'pcachetime': new Date(),
        'songmid': songmid,
        'g_tk': 5381,
        'loginUin': 1337312569,
        'hostUin': 0,
        'format': 'json',
        'inCharset': "utf8",
        'outCharset': "utf-8",
        'notice': 0,
        'platform':' yqq.json',
        'needNewCode': 0
    })
    return axios.get(url, {
      params: data
    }).then((res) => {
      return Promise.resolve(res.data)
    })
}